package com.example.demo.equipment.service.impl;

import com.example.demo.equipment.dao.CollectingDevice;
import com.example.demo.equipment.mapper.CollectingDeviceMapper;
import com.example.demo.equipment.service.CollectingDeviceService;
import com.example.demo.system.utility.PageInfo;
import com.example.demo.system.utility.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CollectingDeviceServiceImpl implements CollectingDeviceService {

    @Autowired
    private CollectingDeviceMapper collectingDeviceMapper;

    @Override
    public Result getList(Integer pageNum, Integer pageSize, String name) {
        Integer start = PageInfo.start(pageNum, pageSize);
        List<CollectingDevice> list = collectingDeviceMapper.getList(start, pageSize, name);
        Integer listCount = collectingDeviceMapper.getListCount(name);
        PageInfo info = new PageInfo(pageNum, pageSize, listCount, list);
        return Result.success(info);
    }

    @Override
    public Result getBindList(List<Integer> ids) {
        List<CollectingDevice> collectingDevices = collectingDeviceMapper.getBindList(ids);
        return Result.success(collectingDevices);
    }

    @Override
    public CollectingDevice get(Integer id) {
        return collectingDeviceMapper.get(id);
    }

    @Override
    public Result add(CollectingDevice collectingDevice) {
        collectingDevice.setModifyTime(new Date());
        collectingDeviceMapper.add(collectingDevice);
        return Result.success("新增成功");
    }

    @Override
    public Result update(CollectingDevice collectingDevice) {
        collectingDevice.setModifyTime(new Date());
        collectingDeviceMapper.update(collectingDevice);
        return Result.success("修改成功");
    }

    @Override
    public Result delete(Integer id) {
        collectingDeviceMapper.delete(id);
        return Result.success("删除成功");
    }

}
